package com.fpd.sharding.config;

import java.util.Collection;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyPreciseShardingAlgorithm implements PreciseShardingAlgorithm<String> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
        // 分片健的值
        String time = preciseShardingValue.getValue();
        System.out.println("=======time==="+time);
        // 匹配到对应的库/表
        for (String name : collection) {
            if (name.equals(time)) {
                log.info("========分片索引：{}",time);
                System.out.println("=======分片索引==="+time);
                return name;
            }
        }
        return null;
    }
}
